<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <!--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="strategy"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大攻略管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题/副标题">
                </div>
                <button type="submit" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <button type="button" class="btn btn-success updateBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加攻略
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>封面</th>
                    <th>攻略标题</th>
                    <th>副标题</th>
                    <th>所属地区</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <#list result.list as entity>
                <tr>
                    <td><img src="${entity.coverUrl!}"  width="100px"/> </td>
                    <td>${entity.title!}</td>
                    <td>${entity.subTitle!}</td>
                    <td>${(entity.place.name)!}</td>
                    <td>${(entity.stateName)!}</td>
                    <td><a href="javascript:;" class="updateBtn" data-json='${entity.jsonString}'>修改</a></td>
                </tr>
                </#list>
            </table>
           <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategy/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <input type="hidden" name="coverUrl"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入标题"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">副标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="subTitle" placeholder="请输入副标题"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100px"/>
                            <input type="file" class="form-control" name="image"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">所属地区：</label>
                        <div class="col-lg-6">
                            <select type="text" class="form-control" name="place.id">
                                <#list places as p>
                                    <option value="${p.id}">${p.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">状态：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="state">
                                <option value="1">正常</option>
                                <option value="2">推荐</option>
                                <option value="3">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>



<script>
    $(".updateBtn").click(function () {
        $("#editForm").clearForm(true);
        var json = $(this).data("json");
        if(json){
            $("#editForm input[name=id]").val(json.id);
            $("#editForm input[name=title]").val(json.title);
            $("#editForm input[name=subTitle]").val(json.subTitle);
            $("#coverUrl").attr("src", json.coverUrl);
            $("#editForm input[name=coverUrl]").val(json.coverUrl);
            $("#editForm select[name='place.id']").val(json.placeId);
            $("#editForm select[name=state]").val(json.state);
        }
        $("#inputModal").modal("show");
    });

    $(".saveBtn").click(function () {
        $("#editForm").ajaxSubmit(function (data) {
            console.log(data);
            if (data.success) {
                reload();
            } else {
                $.message.alert("提示", data.msg);
            }
        });
    });
</script>
</body>
</html>